package com.th.therp.mapper;

import com.th.therp.pojo.dto.UpdateUserDto;
import com.th.therp.pojo.emtity.User;
import com.th.therp.pojo.dto.UserDto;
import com.th.therp.pojo.vo.UserVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {

    @Insert("insert into user ( phone,username, password,role, create_time, update_time) values (#{phone},#{username},#{password},0,now(),now())")
    void register(User user);

    @Select("select * from user where phone = #{phone}")
    User findByPhone(UserDto userDto);

    @Select("select * from user where phone= #{phone} and password=#{password}")
    User login(UserDto userDto);

    @Select("select username from user where id=#{userId}")
    String findNameById(Long userId);

    @Update("update user set username = #{username},password = #{password} where id = #{id}")
    void update(UpdateUserDto updateUserDto);

    @Select("select * from user where username = #{username}")
    UserDto findByUsername(String username);

    @Select("select id,username,phone from user where role=0")
    List<UserVo> list();

    @Select("select password from user where id=#{id}")
    String findPassWordById(Integer id);

    @Select("select phone from user where role=1")
    String findAdminPhone();

    @Delete("delete from user where id=#{id}")
    void delete(Integer id);
}